<?php
session_start() ;
if(!isset($_SESSION["login"]) || $_SESSION["login"] == "")
{   
  header("Location: index.php?error=4") ;
}?>

<html>
<head>
<title>Administration</title>
 <link rel="stylesheet" type="text/css" href="style.css" >  
</head>

<body>
<?php require("menu.php");
require("fonctions.php");
$code=$_GET["error"];
$action=$_GET["action"];
$profil=$_GET["profil"];
?>
<p class="titre">Ajouter un nouvel &eacute;tablissement</p>
<br></br>
<?php echo error_message($code);?>

<?php if($action=="new_dis"){

	?>
<form action="controler.php?action=add_dis&profil=<?php echo $profil;?>" method="post">
<table class="tab_dis" align="center">

<tr>
	<th class="th1">CODE SIGA</th><th class="th1"><input type="text" name="codesap"></th>
	</tr>
	<tr>
	<th class="th1">ETABLISSEMENT</th><th class="th1"><input type="text" name="distributeur"></th>
	</tr>
	<tr>
	<th class="th1">GROUPE</th><th class="th1"><input type="text" name="groupe"></th>
	</tr>
	<tr>
	<th class="th1">ZONE</th><th class="th1"><select name="zone"><option value="0"></option>
	<option value="1">ZONE NORD</option>
	<option value="2">ZONE SUD</option>
	</select></th>
	</tr>
	<tr>
	<th class="th1">RESEAU</th><th class="th1">
	<select name="reseau"><option value="0"></option>
	<option value="1">RESEAU PRIVE</option>
	<option value="2">RTCE</option>
	</select>
	</th>
	</tr>
	<tr>
	<th class="th1">Nom du Manager</th><th class="th1">
	<select name="id_manager">
	<option></option>
		<?php $sql="select * from managers";
		$res = mysql_query($sql);
		while($r = mysql_fetch_object($res)){
		?>
		<option value="<?php echo $r->id;?>"><?php echo "$r->nom - $r->prenom"?></option>
		
		<?php }?>
	</select>
	
	</th>
	</tr>
	<tr>
	<th class="th1">IDENTIFIANT</th><th class="th1">
	<input type="text" name="login"></input>
	</th>
</tr>
<tr>
	<th class="th1">MOT DE PASSE</th><th class="th1">
	<input name="mdp" type="password"></input>
	</th>
</tr>
<tr>
	<td colspan=2 align=center></td>
</tr>
<tr>
	<td colspan=2 align=center><input type="submit" value="Enregistrer"></td>
</tr>
</table>
</form>

<?php }

if($action=="mod_dis_new"){
$id_dis = $_GET["id_dis"];

$sql="select * from distributeurs where id=$id_dis";
$res = mysql_query($sql);
$row = mysql_fetch_object($res);
$t_man = explode (",",getManagernameById(getIdManagerByDis($row->id)));
$val = "$t_man[0] $t_man[1]";
	?>
<form action="controler.php?action=mod_dis_new&id_dis=<?php echo $id_dis;?>&profil=<?php echo $profil;?>" method="post">
<input type="hidden" name="profil" value="<?php echo $profil?>">
<table class="tab_dis" align="center">

<tr>
	<th class="th1">CODESAP</td><th class="th1"><input type="text" name="codesap" value="<?php echo $row->codesap;?>" disabled></td>
	</tr>
	<tr>
	<th class="th1">ETABLISSEMENT</td><th class="th1"><input type="text" name="distributeur" value="<?php echo $row->nom;?>" ></td>
	</tr>
	<tr>
	<th class="th1">GROUPE</td><th class="th1"><input type="text" name="groupe" value="<?php echo $row->groupe;?>" ></td>
	</tr>
	<tr>
	<th class="th1">ZONE</td><th class="th1"><select name="zone"><option value="0"></option>
	<option value="1" <?php if($row->id_zone==1) echo "selected";?>>ZONE NORD</option>
	<option value="2" <?php if($row->id_zone==2) echo "selected";?>>ZONE SUD</option>
	</select></td>
	</tr>
	<tr>
	<th class="th1">RESEAU</td><th class="th1">
	<select name="reseau"><option value="0"></option>
	<option value="1" <?php if($row->id_reseau==1) echo "selected";?>>RESEAU PRIVE</option>
	<option value="2" <?php if($row->id_reseau==2) echo "selected";?>>RTCE</option>
	</select>
	</td>
	</tr>
	<tr>
	<th class="th1">Nom du Manager</td><th class="th1"><input type="text" name="nom_manager" value="<?php echo $val; ?>" ></td>
</tr>
<tr>
	<td colspan=2 align=center></td>
</tr>
<tr>
	<td colspan=2 align=center><input type="submit" value="Enregistrer"></td>
</tr>
</table>
</form>


<?php }?>

</body>

</html>
